﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Evan.Common
{
    /// <summary>
    /// 字符串转换编码 替换模式 系统关键类
    /// </summary>
    public static class TransCode
    {
        /// <summary>
        /// 关键字文字编码
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public static string StrEnCode(string Str)
        {
            Str = Str.Replace("_FLAG_CONTENT_ENCODE_", ""); //替换编码头标示
            Str = Str.Replace("[", "_MPBRACKETS_").Replace("]", "_MNBRACKETS_"); //[]
            Str = Str.Replace("{", "_BPBRACKETS_").Replace("}", "_BNBRACKETS_"); //{}
            Str = Str.Replace("(", "_SPBRACKETS_").Replace(")", "_SNBRACKETS_"); //()
            Str = Str.Replace("<", "_TPBRACKETS_").Replace(">", "_TNBRACKETS_"); //<>
            Str = Str.Replace("%", "_PERCENTSS_").Replace("&", "_ANDS_"); //%&
            Str = Str.Replace("\"", "_DOUBLEQUOTES_").Replace("'", "_APOSTROPHE_"); //"'
            Str = Str.Replace("/", "_SLASHS_").Replace("\\", "_BACKSLASHS_"); // /(斜杠) \反斜杠
            Str = Str.Replace(":", "_COLONS_").Replace(";", "_SEMICOLONS_"); // 冒号+分号
            Str = Str.Replace("\n", "_WRAPS_").Replace("\t", "_TABSS_").Replace("\r", "_ENTERS_").Replace("\r\n", "_ENTERSWRAPS_");
            Str = Str.Replace("©", "_COPYRIGHT_").Replace("=", "_EQUAL_"); // 版权符号 等于号
            Str = Str.Replace("+", "_PLUS_").Replace("-", "_MINUS_"); //加号减号
            Str = Str.Replace("*", "_MULTIPLICATION_"); //乘号
            Str = Str.Replace("~", "_WAVE_").Replace("!", "_SIGH_").Replace("@", "_AITS_").Replace("#", "_WELL_").Replace("$", "_DOLLAR_").Replace("^", "_WORDOFF_");
            return Str;
        }
        /// <summary>
        /// 关键字文字解码
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public static string StrDeCode(string Str)
        {
            Str = Str.Replace("_MPBRACKETS_", "[").Replace("_MNBRACKETS_", "]"); //[]
            Str = Str.Replace("_BPBRACKETS_", "{").Replace("_BNBRACKETS_", "}"); //{}
            Str = Str.Replace("_SPBRACKETS_", "(").Replace("_SNBRACKETS_", ")"); //()
            Str = Str.Replace("_TPBRACKETS_", "<").Replace("_TNBRACKETS_", ">"); //<>
            Str = Str.Replace("_PERCENTSS_", "%").Replace("_ANDS_", "&"); //%&
            Str = Str.Replace("_DOUBLEQUOTES_", "\"").Replace("_APOSTROPHE_", "'"); //"'
            Str = Str.Replace("_SLASHS_", "/").Replace("_BACKSLASHS_", "\\"); // /(斜杠) :冒号  \反斜杠
            Str = Str.Replace("_COLONS_", ":").Replace("_SEMICOLONS_", ";"); // 冒号+分号
            Str = Str.Replace("_WRAPS_", "\n").Replace("_TABSS_", "\t").Replace("_ENTERS_", "\r").Replace("_ENTERSWRAPS_", "\r\n");
            Str = Str.Replace("_COPYRIGHT_", "©").Replace("_EQUAL_", "=");
            Str = Str.Replace("_PLUS_", "+").Replace("_MINUS_", "-");
            Str = Str.Replace("_MULTIPLICATION_", "*");
            Str = Str.Replace("_WAVE_", "~").Replace("_SIGH_", "!").Replace("_AITS_", "@").Replace("_WELL_", "#").Replace("_DOLLAR_", "$").Replace("_WORDOFF_", "^");
            return Str;
        }
    }
}
